<?php

namespace Index\Controller;

use Think\Controller;

class IndexController extends Controller {

    public function index() {
        return $this->display();
    }

    public function login_up() {
//        $where['account'] = I('account');
//        $where['email'] = I('account');
//        $where['mobile'] = I('account');
//        $where['_logic'] = 'OR';
//
//        $checkinfo['_complex'] = $where;
        $checkinfo['mobile'] = I('mobile');
        $checkinfo['password'] = md5(I('password'));
        //$checkinfo['password'] = array('eq', md5(I('password')));

        $usertype = I('usertype');
        $checkbox = I('remcheckbox'); //两周内免登陆


        $db = new \Common\DAL\DB();
        if ($usertype == '个人会员') {
//            $count = $db->count('user', $checkinfo);
            $arr = M('user')->where($checkinfo)->find();
        } else if ($usertype == '企业会员') {
//            $count = $db->count('enterprise', $checkinfo);
            $arr = M('enterprise')->where($checkinfo)->find();
        }
        if ($arr) {
            $array_cookie['account'] = I('account');
            cookie('id', $arr['id']);
            cookie('nick', $arr['nick']);
            if ($checkbox == 'on') {//两周内免登录
                cookie('account', $array_cookie, 3600 * 24 * 14); //保存cookie两周
            } else {
                cookie('account', $array_cookie);
            }
            $result['flag'] = true;
            $result['msg'] = "登录成功";
            //$result['redirect'] = url('');
        } else {
            $result['flag'] = false;
            $result['error'] = "用户名或密码不正确";
        }

        $this->ajaxReturn($result, 'json');
    }

}
